// pages/collect/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabsList:[
      {
        id:0,
        name:"商品收藏",
        isActive:true
      },
      {
        id:1,
        name:"品牌收藏",
        isActive:false
      },
      {
        id:2,
        name:"店铺收藏",
        isActive:false
      },
      {
        id:3,
        name:"浏览足迹",
        isActive:false
      },
    ],
    goodsList:[],
    btnData:[
      {
        id:0,
        name:"全部",
        isActive:true
      },
      {
        id:1,
        name:"正在热卖",
        isActive:false
      },
      {
        id:2,
        name:"即将上线",
        isActive:false
      }
    ],
    clickIndex:0
  },   
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let goodsList = wx.getStorageSync('coll') 
    this.setData({
      goodsList
    })
  },

  // 切换 tabs
  handCut(e){
    let {tabsList} = this.data
    let {index} = e.detail 
    tabsList.forEach( (v,i) => {
       i == index ? v.isActive = true : v.isActive =false 
    });
    this.setData({
      tabsList
    })
    
  },

  // 单击热卖
  handBtn(e){
    let { index } = e.currentTarget.dataset
    // console.log(clickIndex);
    let  {btnData,clickIndex} = this.data
    btnData.forEach( (v,i) => i == index ? v.isActive = true : v.isActive = false ) 
    this.setData({
      btnData,
      clickIndex:index
    })
  }
 
})